package com.example.lizhanqi.livevideo.ui.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.Toast;

import com.example.lizhanqi.livevideo.R;
import com.example.lizhanqi.livevideo.adaputer.TabLayoutAdaputer;

public class HomeFragment extends Fragment implements View.OnClickListener {
    private View view;
    private TabLayout tab_findFragment_title;
    private ViewPager vp_findFragment_pager;
    private ImageButton btn_search;
    private TabLayout home_tablayout;
    private ImageButton btn_other;
    private ViewPager home_viewPage;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container, false);
        initView(view);
        return view;
    }
    private void initView(View view) {
        String[] titles = new String[]{"最新", "热门" ,"关注"};
        Fragment[] fragments= new Fragment[]{new LatestFragment(),new HotFragment(),new FocusFragment()};
        btn_search = (ImageButton) view.findViewById(R.id.btn_search);
        home_tablayout = (TabLayout) view.findViewById(R.id.home_tablayout);
        //1.MODE_SCROLLABLE模式
        home_tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        btn_other = (ImageButton) view.findViewById(R.id.btn_other);
        home_viewPage = (ViewPager) view.findViewById(R.id.home_viewPage);
        home_tablayout.setupWithViewPager(home_viewPage);//给tablayout设置viewpager对象
        home_viewPage.setAdapter(new TabLayoutAdaputer(getFragmentManager(),fragments,titles));
        btn_search.setOnClickListener(this);
        btn_other.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_search:
                Toast.makeText(getActivity(), "搜索", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_other:
                Toast.makeText(getActivity(), "其他", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
